package com.foodost.cwpstrokes;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class InitService extends Service {
    private static final String TAG = InitService.class.getSimpleName();
    private boolean isNeed = false;
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if(isNeed){
            InitWordTask wordTask = new InitWordTask();
            wordTask.execute(this);
        }else{
            CWPStrokesModel model = new CWPStrokesModel(this);
            Log.d(TAG, "start time");
            model.copyDatabaseFile(this, true);
            Utils.cwpstrokesInitFilish(this);
            Log.d(TAG, "end time");
            model.getHanziListByGrage(this, 0, false);
            model.getHanziListByGrage(this, 1, false);
            Intent in = new Intent();
            in.setClass(this, MainActivity.class);
            in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            this.startActivity(in);
            this.stopSelf();
        }
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

}
